package com.caimore.logger;

import com.caimore.common.SmsUtils_sdk;
import com.caimore.logger.LoggerThread;
import java.io.File;

public final class Logger {

   private static boolean m_bInit = false;
   private static Logger.ELogLevel m_eLogLevel = Logger.ELogLevel.INFO;
   private static int m_iLogOutput = 1;
   private static String m_sLogPath;
   private static LoggerThread m_thdLogger;


   public static boolean init(String _sLogLevel, int _iLogOutput) {
      if(m_bInit) {
         return false;
      } else {
         m_bInit = true;
         m_eLogLevel = Logger.ELogLevel.valueOf(_sLogLevel.toUpperCase().trim());
         m_iLogOutput = _iLogOutput;
         if((m_iLogOutput & 2) == 2) {
            try {
               String e = "./log/";
               File fileLogPath = new File(e);
               if(!fileLogPath.exists()) {
                  fileLogPath.mkdir();
               }

               m_sLogPath = e;
            } catch (Exception var4) {
               return false;
            }

            m_thdLogger = new LoggerThread(m_sLogPath);
            m_thdLogger.start();
         }

         return true;
      }
   }

   public static void debug(String _sLog) {
      _log(Logger.ELogLevel.DEBUG, _sLog);
   }

   public static void info(String _sLog) {
      _log(Logger.ELogLevel.INFO, _sLog);
   }

   public static void warning(String _sLog) {
      _log(Logger.ELogLevel.WARN, _sLog);
   }

   public static void error(String _sLog) {
      _log(Logger.ELogLevel.ERROR, _sLog);
   }

   public static void fatal(String _sLog) {
      _log(Logger.ELogLevel.FATAL, _sLog);
   }

   private static void _log(Logger.ELogLevel _eLogLevel, String _sLog) {
      if(m_eLogLevel.compareTo(_eLogLevel) <= 0) {
         String sLog = "[" + _eLogLevel.toString() + "][" + SmsUtils_sdk.getNowTimeString() + "]" + _sLog;
         if((m_iLogOutput & 1) == 1) {
            System.out.println(sLog);
         }

         if((m_iLogOutput & 2) == 2) {
            m_thdLogger.pushLog(sLog);
         }
      }

   }

   public static enum ELogLevel {

      DEBUG,
      INFO,
      WARN,
      ERROR,
      FATAL;
      // $FF: synthetic field
      private static final Logger.ELogLevel[] ENUM$VALUES = new Logger.ELogLevel[]{DEBUG, INFO, WARN, ERROR, FATAL};


   }
}
